/**
 * 初始化员工工资详情对话框
 */
var PayrollInfoDlg = {
    payrollInfoData : {}
};

/**
 * 清除数据
 */
PayrollInfoDlg.clearData = function() {
    this.payrollInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
PayrollInfoDlg.set = function(key, val) {
    this.payrollInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
PayrollInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
PayrollInfoDlg.close = function() {
    parent.layer.close(window.parent.Payroll.layerIndex);
}

/**
 * 收集数据
 */
PayrollInfoDlg.collectData = function() {
    this
    .set('id')
    .set('username')
    .set('usercode')
    .set('platform')
    .set('entryTime')
    .set('basicSalary')
    .set('bonus')
    .set('attendanceDays')
    .set('actualBasicSalary')
    .set('actualBonus')
    .set('performanceBonus')
    .set('commission')
    .set('norepair Bonus')
    .set('otherSubsidies')
    .set('leaveDays')
    .set('leaveDeduction')
    .set('lateArrivals')
    .set('letaDeduction')
    .set('otherDeduction')
    .set('advancePiso')
    .set('advanceRmb')
    .set('realRmb')
    .set('send Psio')
    .set('roomSupplement')
    .set('realPiso')
    .set('payTime')
    .set('remarks')
    .set('creattime')
    .set('updatetime');
}

/**
 * 提交添加
 */
PayrollInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/payroll/add", function(data){
        Feng.success("添加成功!");
        window.parent.Payroll.table.refresh();
        PayrollInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
	
    ajax.set(this.payrollInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
PayrollInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/payroll/update", function(data){
        Feng.success("修改成功!");
        window.parent.Payroll.table.refresh();
        PayrollInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.payrollInfoData);
    ajax.start();
}

/**
* 上传文件
*/
PayrollInfoDlg.uploadSubmit = function() {debugger
    console.log(document.getElementById('inPut').files)
    var inputData = document.getElementById('inPut').files[0]
    var formData = new FormData();
    formData.append("file",inputData);
	$.ajax({
			   url: "/payroll/upload",
			   data: formData,
			   type: "Post",
			   dataType: "json",
			   cache: false,//上传文件无需缓存
			   processData: false,//用于对data参数进行序列化处理 这里必须false
			   contentType: false, //必须
                success:function () {
                    alert("上传成功！");
                },
                error:function (data) {
                    alert("上传失败"+data.responseJSON.message + "!");
                }
    });
	
   
}

$(function() {

});
